<?php namespace system\model;
//	框架的核心模型类	
	use hdphp\model\Model;
	
//	模型类：类型表模型
	class Orders extends Model{
		protected $table='orders';
//		类型名验证
		protected $validate = [
        ['consignee','required','姓名不能为空',3,3]
    ];
		public function store(){
			if(!$this->create()) return false;
//			添加订单
			$orderData=array(
				'number'=>\Cart::getOrderId(),
				'consignee'=>$_POST['consignee'],
				'address'=>$_POST['receivingAddress'],
				'mobile'=>$_POST['receivingMobilePhone'],
				'total'=>$_SESSION['shop']['zj'],
				'time'=>time(),
				'remark'=>'',
				'uid'=>$_SESSION['id'],
				'status'=>'货到付款'
			);
//			p($orderData);die;
			$oid = $this->add($orderData);
			$_SESSION['oid']=$oid;
//			添加订单列表
			$orderlist=new \system\model\Orderlist;
			foreach($_SESSION['shop']['goods'] as $k=>$v){
				$com=implode('|',$v['options']['combine']);
				$data=Db::table('goods_list')->where('combine',$com)->first();
				$orderlisrData=array(
					'quantity'=>$v['num'],
					'subtotal'=>$v['total'],
					'explain'=>'',
					'gid'=>$v['id'],
					'oid'=>$oid,
					'glid'=>$data['glid'],
					'glnumber'=>$data['number']
				);
				
				$orderlist->add($orderlisrData);
			}
			return true;
		}
		
	}